<!--消息配置维护-->
<template>
  <div class="app-container">
    <ht-search-form
      v-show="showSearch"
      :dictMap="dictMap"
      :labelWidth="100"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      :defaultEventKey="defaultEventKey"
    ></ht-search-form>
    <ht-table
      ref="dataTable"
      rowKey="msgId"
      :showSerialNumber="false"
      :multi-select="false"
      :dictMap="dictMap"
      :reqConfig="reqConfig"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="120px" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '修改',
                  doFunc: () => {
                    edit(scope.row);
                  },
                },
                {
                  label: '删除',
                  doFunc: () => {
                    del(scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <msg-conf-add-dialog ref="msgConfAddDialog" @editComplete="editComplete"></msg-conf-add-dialog>

    <msg-conf-edit-dialog ref="msgConfEditDialog" @editComplete="editComplete"></msg-conf-edit-dialog>
  </div>
</template>
<script>
import {
  msgConfMaintainUrlConfig,
  msgConfDelete,
  getMonitorConfList,
  getMsgGroupList,
} from "@/api/cnaps/bizMng/msgConf.js";
import { listPageMixin } from "@/libs/listPageMixin";
import msgConfAddDialog from "./addDialog";
import msgConfEditDialog from "./editDialog";

export default {
  name: "msgConf_maintain",
  mixins: [listPageMixin],
  components: {
    msgConfAddDialog,
    msgConfEditDialog,
  },
  props: {},
  data() {
    return {
      reqConfig: msgConfMaintainUrlConfig,
      defaultEventKey: "",
      eventTypeList: [],
      msgGroupList: [],
      //数据字典
      searchFormDictList: ["ON_OFF_STATUS", "MSG_SEND_TYPE"],
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "",
      showSearch: true,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        eventType:"",
        sendType:"",
        isUse:""
      },
      formOptions: [],
      opButtonList: () => {
        return [
          {
            label: "新增",
            type: "primary",
            icon: "el-icon-plus",
            actionType: "add",
            clickFun: () => {
              this.add();
            },
          },
        ];
      },
      tableBindColumns: [
        {
          label: `事件类型`,
          prop: "eventType",
          width: "200px",
          align: "center",
          formatter: (row) => {
            if (!row.eventType) {
              return "-";
            }
            return row.eventNm;
          },
        },
        { label: `启用标识`, prop: "isUse", align: "center", dictCode: "ON_OFF_STATUS" },

        // { label: `节假日开关`, prop: "holidayFlag", width: "120px", align: "center"},
        // { label: `发送开始时间`, prop: "sendStartDt", width: "120px", align: "center"},
        // { label: `发送结束时间`, prop: "sendEndDt", width: "120px", align: "center"},
        {
          label: `通知类型`,
          prop: "sendType",
          width: "200px",
          align: "center",
          formatter(row) {
            let sendTypeName = "";
            let sendType = row.sendType;
            if (sendType === "01") {
              sendTypeName = "01-邮件通知";
            } else if (sendType === "02") {
              sendTypeName = "02-短信通知";
            } else if (sendType === "01,02" || sendType === "02,01") {
              sendTypeName = "01-邮件通知,02-短信通知";
            }
            return sendTypeName;
          },
        },
        {
          label: `邮件接收人小组`,
          prop: "mailRecGroup",
          width: "300px",
          align: "center",
          formatter(row) {
            return row.mailRecGroupNm;
          },
        },
        {
          label: `邮件抄送人小组`,
          prop: "mailCopyGroup",
          width: "300px",
          align: "center",
          formatter(row) {
            return row.mailCopyGroupNm;
          },
        },
        {
          label: `短信接收人小组`,
          prop: "smsRecGroup",
          width: "300px",
          align: "center",
          formatter(row) {
            return row.smsRecGroupNm;
          },
        },
        { label: `创建操作员`, prop: "creator", align: "center",width: "150px" },
        { label: `创建时间`, prop: "createdTime", align: "center", type: "date" },
      ],
    };
  },
  mounted() {
    // this.getList()
    this.formOptions = [
      {
        type: "input",
        prop: "eventType",
        defaultAttr: {
          label: "事件类型",
          placeholder: "请输入事件类型",
        },
      },
      {
        type: "dict",
        dict: "MSG_SEND_TYPE",
        prop: "sendType",
        defaultAttr: {
          label: "通知类型",
          placeholder: "请选择通知类型",
        },
      },
      {
        type: "dict",
        dict: "ON_OFF_STATUS",
        prop: "isUse",
        defaultAttr: {
          label: "启用标识",
          placeholder: "请选择启用标识",
        },
      },
    ];
    this.initEventTypeList();
    this.initMsgGroupList();
  },
  methods: {
    /** todo 查询当天操作员的交易记录 */
    getList() {
      this.doQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    add() {
      console.log("this.$refs.msgConfAddDialog", this.$refs.msgConfAddDialog);
      this.$refs.msgConfAddDialog.show();
    },
    edit(row) {
      console.log("this.$refs.msgConfEditDialog", this.$refs.msgConfEditDialog);
      this.$refs.msgConfEditDialog.show(row);
    },
    del(row) {
      this.$confirm("确认删除该条消息配置维护信息?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return msgConfDelete(row);
        })
        .then(() => {
          this.handleQuery();
          this.msgSuccess("删除提交成功");
        })
        .catch((action) => {});
    },
    editComplete(state) {
      console.log("editComplete", state);
      if (state == true) {
        this.getList();
      }
    },
    //初始化获取监控事件列表
    initEventTypeList() {
      getMonitorConfList(this.queryParams).then((res) => {
        if (res.code === "S") {
          const arr = [];
          const list = res.result || [];
          list.length &&
            list.forEach((v) => {
              arr.push({
                value: v.monitorId,
                text: v.eventNm,
              });
            });
          this.eventTypeList = arr;
        }
      });
    },

    //初始化获取消息分组
    initMsgGroupList() {
      getMsgGroupList(this.queryParams).then((res) => {
        if (res.code === "S") {
          const arr = [];
          const list = res.result || [];
          list.length &&
            list.forEach((v) => {
              arr.push({
                value: v.groupId,
                text: v.groupNm,
              });
            });
          this.msgGroupList = arr;
        }
      });
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}
</style>
